package com.interphone.beta.socket;

import java.io.*;
import java.net.*;

class UDPServer extends Thread {

	DatagramSocket serverSocket;
	String port;

	UDPServer() {}
	
	public void run(){
		try {
			serverSocket = new DatagramSocket(8000);
			byte[] receiveData = new byte[1024];
			byte[] sendData = new byte[1024];
			System.out.println(serverSocket.getLocalPort() + ":"
					+ serverSocket.getRemoteSocketAddress() + ":"
					+ serverSocket.getPort());
			int nb = 0;
			while (nb++ < 10) {
				receiveData = new byte[1024];
				DatagramPacket receivePacket = new DatagramPacket(receiveData,
						receiveData.length);
				serverSocket.receive(receivePacket);
				String sentence = new String(receivePacket.getData());
				//System.out.println("RECEIVED: " + sentence);
				port = receivePacket.getSocketAddress().toString().split(":")[1];
				System.out.println("Port de départ du flux UDP"+port);
			}
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public String getPort() {
		return port;
	}

}